package com.mytomcat.catalina.connector;

import com.mytomcat.catalina.lifecycle.LifeCycleBase;
import com.mytomcat.catalina.net.AbstractEndpoint;
import com.mytomcat.catalina.service.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 连接器接口
 *
 * @author supu
 * @date 2019-04-22 10:56
 **/
public class Connector extends LifeCycleBase {
    private static final Logger LOGGER = LoggerFactory.getLogger(Connector.class);

    private int port;
    private String protocol = "HTTP/1.1";

    private Service service;

    private final AbstractEndpoint abstractEndpoint;

    public Connector(AbstractEndpoint abstractEndpoint) {
        this.abstractEndpoint = abstractEndpoint;
    }

    public Service getService() {
        return service;
    }

    public void setService(Service service) {
        this.service = service;
    }

    @Override
    protected void startInternal() {
        LOGGER.info("Connector start");

        // 启动Endpoint
        abstractEndpoint.setConnector(this);
        abstractEndpoint.start();
    }

    @Override
    protected void stopInternal() {
        LOGGER.info("Connector stop");
    }

    @Override
    protected void destroyInternal() {
        LOGGER.info("Connector destroy");
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public String getProtocol() {
        return protocol;
    }

    public void setProtocol(String protocol) {
        this.protocol = protocol;
    }
}
